<?php
/*
 * 用户金额日志
 */
defined('IN_YuLin') || exit('NO PERMIT!');

UserLogin();
$res          = array();
$operation    = $_POST['operation'] ? $_POST['operation'] : 'alllog';
$userInfo     = $_user;
$type         = NoBadStr($_POST['type']);
switch ($operation){
    case 'alllog':
        $moneylogWhe = ' WHERE 1 ';
        // 如果是代理商查询投注记录
        if ($type){
            if ($type == 'agent_all'){
                $userLineData = array();
                getUserLine($_uid, $userLineData);
                $moneylogWhe .= ' AND uid IN (' . implode(',', array_keys($userLineData)) . ')';
            }else{
                // 指定查询某个用户的投注
                $sql         = 'SELECT id FROM ' . Table('user') . ' WHERE username = "' . $type . '"';
                $tagUserInfo = $db->getrow($sql);
                if ($tagUserInfo){
                    $moneylogWhe .= ' AND uid = ' . $tagUserInfo['id'];
                }else{
                    $moneylogWhe .= ' AND uid = ' . $_uid;
                }
            }
        }else{
            $moneylogWhe .= ' AND uid = ' . $_uid;
        }
        
        // 查询用户的充值记录
        $moneylogTab   = Table('user_money_log');
        $moneylogWhe  .= ' AND dateline >= ' . strtotime(date('Y-m-d', strtotime("-1 week")));
        $orderby       = ' ORDER BY id DESC ';
        $sql = 'SELECT id, tid, lkey, money, balance, freeze, total, balance_old, freeze_old, total_old, dateline, ip, notes FROM '. $moneylogTab . $moneylogWhe . $orderby;
        $moneylogList  = $db->getall($sql);
        foreach ($moneylogList as $k => $v){
            $moneylogList[$k]['dateline_format'] = date('Y-m-d H:i:s', $v['dateline']);
        }
        $res['status'] = 'success';
        $res['list']   = $moneylogList;
        $res['other']  = array(
            'today'     => strtotime(date('Y-m-d')),
            'yesterday' => strtotime(date('Y-m-d', strtotime("-1 day")))
        );
        break;
    default:
        break;
}

echo json_encode($res);


